import Vue from 'vue'
import VueRouter from 'vue-router'
import Loading from '../views/Loading.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Loading',
    component: Loading,
    meta:{
      isNav:true,
      isTabBar:true
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
    meta:{
      isTabBar:true
    }
  },
  {
    path: '/articleList',
    name: 'ArticleList',
    component: () => import('../views/ArticleList.vue')
  },
  {
    path: '/articleDetail',
    name: 'ArticleDetail',
    component: () => import('../views/ArticleDetail.vue'),
    meta:{
      isTabBar:true
    }
  },
  {
    path: '/movieList',
    name: 'MovieList',
    component: () => import('../views/MovieList.vue')
  },
  {
    path: '/movieDetail',
    name: 'MovieDetail',
    component: () => import('../views/MovieDetail.vue'),
    meta:{
      isTabBar:true
    }
  },
  {
    path: '/movieMore',
    name: 'MovieMore',
    component: () => import('../views/MovieMore.vue')
  },
  {
    path: '/center',
    name: 'Center',
    component: () => import('../views/Center.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
var vm = new Vue()
router.beforeEach((to,from,next)=>{
  var auth = vm.$cookie.get('loginAuth')   // 使用vue-cookie获取cookie
  if(to.path=='/login'){
    if(auth){
      router.push('/')
    }else{
      next()
    }
  }else{
    if(auth){
      next()
    }else{
      router.push('/login')
    }
  }
})
export default router
